package com.scujj.util;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.scujj.pojo.Result;

import java.util.HashMap;
import java.util.List;

public class PageUtil<T> {
    public Result pageOrder(Page<T> page) {
        List<T> goodsList = page.getRecords();
        return toResult(page,goodsList);
    }

    public Result objectPageOrder(Page<T> page,List<T> list){
        return toResult(page, list);
    }

    private Result toResult(Page<T> page, List<T> list) {
        Long pageCount = page.getPages();
        Long total = page.getTotal();
        HashMap<String, Object> data = new HashMap<>();
        data.put("entityList", list);
        data.put("pageCount", pageCount);
        data.put("total", total);
        return Result.success(data);
    }
}
